package com.companyname.projecttemplate.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import com.base.core.context.annotation.RestfulCheck;
import com.base.core.head.ao.WsMessageAO;
import com.base.core.mvc.web.BaseWebController;
import com.base.core.mvc.ws.WsMessageTemplate;
import com.companyname.common.SendService;
import com.companyname.projecttemplate.mapping.ApiMapping;
import com.gitee.magic.framework.head.vo.BaseVO;

/**
 * @author start
 */
@RestController
public class ApiController extends BaseWebController implements ApiMapping {

	@Autowired
	private SendService sendService;
	@Autowired
	private WsMessageTemplate wsMessageTemplate;
	
	@RestfulCheck
	@Override
	public BaseVO wsConnection(Long userId) {
		return response();
	}

	@RestfulCheck
	@Override
	public BaseVO wsHandleMessage(WsMessageAO<String> ao) {
		wsMessageTemplate.onMessage(ao, (s)->{
			sendService.send(ao.getUserId(),s);
		});
		return response();
	}

}
